﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;

public class GameFunctions : MonoBehaviour 
{
	public static void OnAPIError(PlayFabError error)
	{
		Debug.Log (error);
	}
		
	public static void OpenMenu(GameObject[] menu, int index)
	{	
		for (int i = 0; i <= menu.Length-1; i ++)
		{	
			if (menu[i] != null)
			menu [i].SetActive (i == index);			
		}

	}
	public static string RandomString(int length)
	{	
		System.Random random = new System.Random();
		string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		char[] stringChars = new char[length];
		for (int i = 0; i < stringChars.Length; i++)
		{
			stringChars[i] = chars[random.Next(chars.Length)];
		}

		string finalString = new String(stringChars);
		return finalString;
	}

	public static void DestroyAll()
	{	
		GameObject[] objects = GameObject.FindObjectsOfType<GameObject> ();
		foreach (GameObject obj in objects)
		{
			Destroy (obj);
		}
	}
	public static Vector3 PlanarPosition(Vector3 position,float height)
	{
		return new Vector3(position.x,height,position.z);
	}

	public static float PlanarDistanceBetween(Vector3 position1,Vector3 position2)
	{
		return Vector3.Distance(GameFunctions.PlanarPosition(position1,0),GameFunctions.PlanarPosition(position2,0));
	}

}
